package com.qfedu.tantu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.tantu.dao.ReserveDao;
import com.qfedu.tantu.entity.Reserve;
import com.qfedu.tantu.service.intf.ReserveService;
import com.qfedu.tantu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @Description:
 * @Author: 赵金帅
 * @Date: 2022/07/02/0:30
 */
@Service
public class ReserveServiceImpl implements ReserveService {
    @Resource
    private ReserveDao dao;
    @Override
    public R save(Reserve reserve) {
        //验证参数
        if (reserve!=null){
            QueryWrapper<Reserve> w = new QueryWrapper<>();
            w.eq("idnum",reserve.getIdnum());
            w.eq("token",reserve.getToken());
            Reserve isNull = dao.selectOne(w);
            if (isNull==null){
                /*String peoplename, Integer mun, String phone, Integer idnum, Double housprice, Integer token*/
                Reserve reserve1 = new Reserve(reserve.getPeoplename(),reserve.getMun(),reserve.getPhone(),reserve.getIdnum(),reserve.getHousprice(),reserve.getToken());
                if (dao.insert(reserve1)>0){
                    return R.ok();
                }
            }
        }
        return  R.fail("网络错误！");
    }

    @Override
    public R select(int token) {
        if (token>=0){
            return R.ok(dao.selectList(new QueryWrapper<Reserve>().eq("token",token)));
        }
        return R.fail("无订单");
    }

    @Override
    public R del(Integer id) {
        if (id>0){
           return R.ok(dao.delete(new QueryWrapper<Reserve>().eq("id",id)));
        }
        return R.fail("网络错误！");
    }
}
